import time

import pymysql

# 删除新增成功过期数据
def del_sql(sql_txt):
    conn = pymysql.connect(host="127.0.0.1", user="root", database="social_security", password="753951", charset="utf8")
    cursor = conn.cursor()
    cursor.execute(sql_txt)
    conn.commit()
    cursor.close()
    conn.close()

ts = time.strftime("%H:%M", time.localtime())

while True:
    try:
        if ts == '00:00':
            time.sleep(60)
            # 删除新增成功过期数据
            sql_add_success = 'delete from psn_add_success where status= \'1\';'
            del_sql(sql_add_success)

            # 删除新增错误过期数据
            sql_add_error = 'delete from psn_add_error where status= \'1\';'
            del_sql(sql_add_error)

            # 删除减少成功过期数据
            sql_del_success = 'delete from psn_del_success where status= \'1\';'
            del_sql(sql_del_success)

            # 删除减少错误过期数
            sql_del_error = 'delete from psn_del_error where status= \'1\';'
            del_sql(sql_del_error)

            # 删除回盘过期数据
            sql_unitback = 'delete from unitback where status= \'1\';'
            del_sql(sql_unitback)

    except Exception as e:
        print(e)


